//
//  BJLoginNoticePopView.m
//  CyberWorld
//
//  Created by Sheldon Peng on 2023/9/27.
//  Copyright © 2023 ms. All rights reserved.
//

#import "BJLoginNoticePopView.h"
#import <WebKit/WKWebView.h>

#define titleFont  [UIFont systemFontOfSize:15]
#define appNameFont  [UIFont systemFontOfSize:20]
#define tipColor [UIColor colorWithHexString:@"#4B89F6"]
#define laterBtnColor [UIColor colorWithHexString:@"#ffffff"]
//#import "RichStyleLabel.h"
static CGFloat leftMain = 60;//白色背景离左右距离
static CGFloat appIconWidth = 70;
@interface BJLoginNoticePopView()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) UIView *bottomPopView;
@property (nonatomic,assign) CGFloat bottomPopViewHeight;//视图的高度
 @property (nonatomic,strong)UIImageView *rowIcon;
@property (nonatomic,strong)UILabel *topLabel;
@property (nonatomic,strong)UILabel *decLabel;
@property (nonatomic,strong)UIButton *agreeBtn;
@property (nonatomic,strong)UIButton *laterBtn;
@property (nonatomic,strong)WKWebView *webView;
@end
 

@implementation BJLoginNoticePopView

- (instancetype)init{
    self = [super init];
    if (self) {
        [self initSubViews];
    }
    return self;
}

-(void)initSubViews{
    
    self.bottomPopViewHeight = kScreenH -120;

    [self addSubview:self.bottomPopView];
    self.bottomPopView.makeCons(^{
        make.left.constants(leftMain);
        make.right.constants(-leftMain);
        make.center.constants(0);
    });
    [self.bottomPopView addSubview:self.rowIcon];

    self.rowIcon.makeCons(^{
        make.top.constants(30);
        make.centerX.constants(0);
        make.width.height.constants(62);
    });
    
    [self.bottomPopView addSubview:self.topLabel];
    self.topLabel.makeCons(^{
        make.leading.constants(leftMain);
        make.trailing.constants(-leftMain);
        make.top.view(self.rowIcon).bottom.constants(10);
        make.height.constants(30);
    });
    
    [self.bottomPopView addSubview:self.decLabel];
    self.decLabel.makeCons(^{
        make.leading.constants(23);
        make.trailing.constants(-23);
        make.top.view(self.topLabel).bottom.constants(10);
    });
    
    [self.bottomPopView addSubview:self.agreeBtn];
    self.agreeBtn.makeCons(^{
        make.centerX.constants(0);
        make.top.view(self.decLabel).bottom.constants(20);
        make.width.constants(180);
        make.height.constants(36);
    });

    
    [self.bottomPopView addSubview:self.laterBtn];
    self.laterBtn.makeCons(^{
        make.centerX.constants(0);
        make.top.view(self.agreeBtn).bottom.constants(20);
        make.width.constants(180);
        make.height.constants(36);
        make.bottom.constants(-20);
    });
    
  
}

-(void)showView{
    CGFloat whiteViewWidth = kScreenW-2*leftMain;
    self.frame = [UIScreen mainScreen].bounds;
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.backgroundColor = PopViewBackColor;
//    self.bottomPopView.frame = CGRectMake(leftMain,self.centerY-self.bottomPopViewHeight/2,whiteViewWidth, self.bottomPopViewHeight);
}

#pragma mark - 点击背景关闭视图
-(void)closeView
{
//    self.bottomPopView.frame = CGRectMake(0, kScreenH, kScreenW, self.bottomPopViewHeight);
    [self removeFromSuperview];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}

-(void)agreeBtnClick{
    
    if([self.delegate respondsToSelector:@selector(agreeLoginNoticePopView)])[self.delegate agreeLoginNoticePopView];
    
}



-(UIView *)bottomPopView
{
    if (_bottomPopView == nil) {
        _bottomPopView = [[UIView alloc] init];
        _bottomPopView.backgroundColor = [UIColor whiteColor];
        _bottomPopView.layer.cornerRadius = 12;
        _bottomPopView.layer.masksToBounds = YES;
    }
    return _bottomPopView;
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}

 
-(UIImageView *)rowIcon
{
    if (_rowIcon == nil) {
        _rowIcon = [[UIImageView alloc]init];
        _rowIcon.image = [UIImage imageNamed:@"icon_login"];
    }
    return _rowIcon;
}

-(UILabel *)decLabel
{
    if (_decLabel == nil) {
        _decLabel = [[UILabel alloc]init];
        _decLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        _decLabel.font = [UIFont systemFontOfSize:12];
        _decLabel.textAlignment = NSTextAlignmentCenter;
        _decLabel.text = @"By using our App you agree with our Term of Use and Privacy Policy.";
        _decLabel.numberOfLines = 0;
    }
    return _decLabel;
}
-(UILabel *)topLabel
{
    if (_topLabel == nil) {
        _topLabel = [[UILabel alloc]init];
        _topLabel.textColor =  [UIColor colorWithHexString:@"#000000"];
        _topLabel.textAlignment = NSTextAlignmentCenter;
        _topLabel.font = [UIFont systemFontOfSize:16];
        _topLabel.text = @"MiniScape";
        _topLabel.numberOfLines = 0;
    }
    return _topLabel;
}


-(UIButton *)agreeBtn
{
    if (_agreeBtn == nil) {
        _agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_agreeBtn setBackgroundImage:[UIImage imageNamed:@"icon_login_agreeBtn"] forState:UIControlStateNormal];
        [_agreeBtn addTarget:self action:@selector(agreeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _agreeBtn;
}
-(UIButton *)laterBtn
{
    if (_laterBtn == nil) {
        _laterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_laterBtn setBackgroundImage:[UIImage imageNamed:@"icon_login_cancelBtn"] forState:UIControlStateNormal];
        [_laterBtn addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _laterBtn;
}



@end
